﻿// See https://aka.ms/new-console-template for more information
using DiyEFConfigurationBuilder;
using DiyEFConfigurationBuilder.Enums;

Console.WriteLine("Hello, World!");
string conn = "Server=localhost;port=3306;Database=diyefconfigdb;uid=root;pwd=qwer123456;Character Set=utf8;";
// 未初始化时  EFConfiguration为空
var uninitedConfiguration = EFConfigurationBuilder.EFConfiguration;
// 初始化之后返回 IConfiguration对象
var configuration = EFConfigurationBuilder.Init(conn, DbType.MySql, out string erroMesg);
// 使用GetSection方法获取对应的键值对
var value = configuration.GetSection("Connection").Value;
// 初始化之后的 IConfiguration对象
var initedConfiguration = EFConfigurationBuilder.EFConfiguration;
// 连接对象
var connectionStr = EFConfigurationBuilder.ConnectionStr;

DiyConfig diyConfig = new DiyConfig()
{
    Key = "diy",
    Value = "testDiy"
};
(bool result, string errorMesg) = EFConfigurationBuilder.CreateConfig(diyConfig);

// 等待实体监控事件刷新配置
Thread.Sleep(5 * 1000);

// 刷新之后连接
var value2 = EFConfigurationBuilder.EFConfiguration.GetSection("diy").Value;
var value3 = EFConfigurationBuilder.EFConfiguration.GetSection("Connection1").GetSection("Connection1").Value;
var value4 = EFConfigurationBuilder.EFConfiguration.GetSection("Connection1").Value;
var value5 = EFConfigurationBuilder.EFConfiguration.GetSection("Connection2").Value;
Console.ReadLine();